import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui'
import { Message } from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// 引入axios
import http from './http/http'
// 引入moment模块
import moment from 'moment'

Vue.config.productionTip = false
Vue.use(ElementUI)
// 将封装的axios挂载到全局
Vue.prototype.http = http

// 将api.js挂载到全局
Vue.prototype.$api = require('@/http/api')

http.interceptors.response.use((response) => {
  console.log('进入到响应拦截器');
  if (response.status === 200) {
    // token失效
    if (response.data.code == 202) {
      sessionStorage.clear()
      Message.error('身份信息已过期，请重新登录！')
      router.replace('/login')
    }

  }
  return response

}, (error) => {
  return Promise.reject(error)
})



// 将moment挂载到全局
Vue.prototype.$moment = moment

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
